package com.digitalchina.lxnsy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.ExpertClassificationVO;

import java.util.List;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.adapter
 * 创建人：郑皓
 * 创建时间：2017/2/21 13:51
 * 修改备注：
 * ================================================
 */
public class ExpertSecondAdapter extends BaseAdapter {

    private List<ExpertClassificationVO.ResearchFieldTwoStagesBean> mDatas;
    private Context mContext;
    private final LayoutInflater layoutInflater;
    private int mPosition;


    public ExpertSecondAdapter(Context mContext, List<ExpertClassificationVO.ResearchFieldTwoStagesBean> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
        layoutInflater = LayoutInflater.from(this.mContext);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public ExpertClassificationVO.ResearchFieldTwoStagesBean getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ExpertSecondAdapter.ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ExpertSecondAdapter.ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_mall_type, parent, false);
            viewHolder.textView = (TextView) convertView.findViewById(R.id.item_tv_type);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ExpertSecondAdapter.ViewHolder) convertView.getTag();
        }

        if (mPosition == position) {
            viewHolder.textView.setBackgroundResource(R.drawable.shape_real_time_type);
        } else {
            viewHolder.textView.setBackgroundResource(R.drawable.shape_data_type_null);
        }

        viewHolder.textView.setText(mDatas.get(position).getName());

        return convertView;
    }

    public void setSelectPosition(int position) {
        mPosition = position;
    }

    public ExpertClassificationVO.ResearchFieldTwoStagesBean getCurrentPositionItem() {
        return mDatas.get(mPosition);
    }

    public void setDatas(List<ExpertClassificationVO.ResearchFieldTwoStagesBean> mDatas) {
        this.mDatas = mDatas;
    }

    private static class ViewHolder {
        TextView textView;
    }
}
